package com.cs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cs.domain.IndexImg;
import com.cs.domain.vo.IndexImgVo;
import com.cs.service.IndexImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "轮播图管理的接口")
@RequestMapping("/admin/indexImg")
public class IndexImgController {
    @Autowired
    private IndexImgService indexImgService;

    /**
     * 分页查询轮播图的接口
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询轮播图的接口")
    public ResponseEntity<Page<IndexImg>> findIndexImgPage(Page<IndexImg> page,IndexImg indexImg){
        Page<IndexImg> indexImgPage=indexImgService.findIndexImgPage(page,indexImg);
        return ResponseEntity.ok(indexImgPage);
    }

    /**
     * 加载首页的轮播图
     * @return
     */
    @GetMapping("/indexImgs")
    @ApiOperation(value = "加载首页的轮播图的接口")
    public ResponseEntity<List<IndexImgVo>> loadIndexImgs(){
        List<IndexImgVo> indexImgVos=indexImgService.loadIndexImgs();
        return ResponseEntity.ok(indexImgVos);
    }

    /**
     * 回显轮播图
     * @return
     */
    @GetMapping("/info/{imgId}")
    @ApiOperation("根据id回显轮播图")
    @PreAuthorize("hasAuthority('admin:indexImg:info')")
    public ResponseEntity<IndexImg> findIndexImgBy(@PathVariable Long imgId){
        IndexImg indexImg = indexImgService.findIndexImgBy(imgId);
        return ResponseEntity.ok(indexImg);
    }
}
